package com.hkd.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class TestLife1
 */
@WebServlet("/TestLife2")
public class TestLife2 extends HttpServlet {
    private static final long serialVersionUID = 1L;
    /**
     单例模式 多例模式
     */
    public TestLife2() {
        System.out.println("servlet 创建了");

    }

    public void init(ServletConfig config) throws ServletException {
        System.out.println("servlet 初始化 了");
    }

    public void destroy() {
        System.out.println("servlet 销毁了");
    }
    /**
     * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
            response)
     */
    protected void service(HttpServletRequest request, HttpServletResponse
            response) throws ServletException, IOException {
        System.out.println("servlet 服务启动了");
        String method=request.getMethod();
        if("get".equalsIgnoreCase(method))
            this.doGet(request, response);
        else if("post".equalsIgnoreCase(method))
            this.doPost(request, response);
    }
    @Override

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        PrintWriter out=resp.getWriter();
        out.print("helloworld");
    }
}